#include <xp/bas/stdio.h>
#include <xp/utl/slm.h>


int xp_main (int argc, xp_char_t* argv[])
{
	xp_slm_t slm;

	if (argc != 2) {
		xp_printf (XP_TEXT("usage: %s syslog_message\n"), argv[0]);	
		return -1;
	}

	if (xp_parse_slm (argv[1], &slm, 2005) == -1) {
		xp_printf (XP_TEXT("unparsable message: [%s]\n"), argv[1]);
		return -1;
	}

	if (slm.fldmask & XP_SLM_FLD_PRI) {
		xp_printf (XP_TEXT("Pri: FAC(%d), SEV(%d)\n"), 
			slm.pri.fac, slm.pri.sev);
	}
	if (slm.fldmask & XP_SLM_FLD_TIME) {
		xp_printf (XP_TEXT("Time: %lld\n"), 
			(long long)slm.time);
	}

	if (slm.fldmask & XP_SLM_FLD_HOST) {
		xp_printf (XP_TEXT("Host: %s\n"), slm.host);
	}

	if (slm.fldmask & XP_SLM_FLD_TAG) {
		xp_printf (XP_TEXT("Program: %s\n"), slm.tag);
	}

	if (slm.fldmask & XP_SLM_FLD_PID) {
		xp_printf (XP_TEXT("PID: %lld\n"), (long long)slm.pid);
	}


	if (slm.fldmask & XP_SLM_FLD_TEXT) {
		xp_printf (XP_TEXT("Text: %s\n"), slm.text);
	}


	return 0;
}

